%option noyywrap nodefault
%{
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "crypto/json.h"
#include "crypto/parse/json/json.y.h"
void yyerror(char *);
%}
%%

[+-]?[1-9][0-9]*|0 {
    yylval.number = atoll(yytext);
    // debug printf("%lld as number!\n",atoll(yytext));
    return _JSON_TYPE_NUMBER;
    }
[+-]?(([1-9][0-9]*)|0)"."[0-9]+  {
    yylval.d = atof(yytext);
    // debug printf("%lf as double!\n",atof(yytext));
    return _JSON_TYPE_DOUBLE;;    
    }
NULL {return _JSON_TYPE_NULL;} 
[a-zA-Z][a-zA-Z0-9_]*   {
    int len = strlen(yytext);
    yylval.string = (char*)malloc(len + 1);
    strcpy(yylval.string,yytext);
    yylval.string[len] = '\0';
    // debug printf("%s as Identify!\n",yytext); 
    return _JSON_KEY;
}

\"[^"]*\" {
    int len = strlen(yytext)  - 1;
    yylval.string = (char *)malloc(sizeof(char) * len);
    strcpy(yylval.string, yytext+1);
    yylval.string[len - 1] = '\0';
    // debug printf("%s as string!\n",yytext);
    return _JSON_TYPE_STRING;
    }
[\0\n$] {// debug printf("as EOL\n");
return EOL;}




[ \t] {}

\[ {// debug printf("%c\n", yytext[0]);
return yytext[0];}
\] {// debug printf("%c\n", yytext[0]);
return yytext[0];}
\{ {// debug printf("%c\n", yytext[0]);
return yytext[0];}
\} {// debug printf("%c\n", yytext[0]);
return yytext[0];}
, {// debug printf("%c\n", yytext[0]);
return yytext[0];}
: {// debug printf("%c\n", yytext[0]);
return yytext[0];}

. { 
    //printf("unknown character in input: %c\n", *yytext);
} 
%%
